﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Common;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Data;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraTab;
using ERP_RORZE_SYSTEM;
using ERP_RORZE_TOOL.Common;
using ERP_RORZE_TOOL.Tool.BCThoigianlamviecthang;

namespace ERP_RORZE_TOOL.Tool.NGNoibo
{
    public partial class ucNGNoibo : DevExpress.XtraEditors.XtraUserControl
    {
        DXPopupMenu menu;
        private int reportId = -1;
        public List<GridControl> listGV = new List<GridControl>();
        //public List<GridView> listGC = new List<GridView>();
        //public GridView gridV = new GridView();
        //public string gridViewName;
        public string tabName = string.Empty;

        public ucNGNoibo()
        {
            InitializeComponent();
            InitPopupMenu();
            BindDataReportList();
            BindDataItemList();
            this.dropbtExport.DropDownControl = menu;
            lblFormName.Text = ReportConstants.FormName;
        }

        private void cmbReportList_SelectionChangeCommitted(object sender, EventArgs e)
        {
            ReportConstants.Item item = (ReportConstants.Item)cmbReportList.SelectedItem;
            cmbData.SelectedItem = cmbData.Items[0];
            if (item.Value != -1)
            {
                if (!BindDataToGridview(item.Value))
                {
                    SwitchReport(item.Value);
                }

                reportId = item.Value;
            }
        }

        private void cmbData_SelectionChangeCommitted(object sender, EventArgs e)
        {
            ReportConstants.Item item = (ReportConstants.Item)cmbData.SelectedItem;
            cmbReportList.SelectedItem = cmbReportList.Items[0];
            if (item.Value != -1)
            {

                //gridView1.Columns.Clear();
                //panelBottom.Visible = true;
                this.reportId = item.Value;
                BindDataToGridview(item.Value);
            }
        }

        private bool BindDataToGridview(int reportId)
        {
            bool result = false;
            if (ExistTab(tabControl, reportId))
            {
                foreach (XtraTabPage tabPage in tabControl.TabPages)
                {
                    if (tabPage.Name.Equals("tab" + reportId))
                    {
                        tabPage.Show();
                        break;
                    }
                }
                result = true;

            }
            else
            {
                //gridView1.Columns.Clear();
                XtraTabPage xtratab = new XtraTabPage();
                ucGridView uct = new ucGridView(reportId, this.tabControl, this, this.listGV);
                switch (reportId)
                {
                    case ReportConstants.ReportId.QChartTong_Qty_Crosstab:

                        xtratab.Text = ReportConstants.ReportName.QChartTong_Qty_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QChartTong_Qty_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QChartTong_Qty_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QChartTong_Amount_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QChartTong_Amount_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QChartTong_Amount_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QChartTong_Amount_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QChartNguyenNhan_Qty_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QChartNguyenNhan_Qty_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QChartNguyenNhan_Qty_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QChartNguyenNhan_Qty_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QChartNguyenNhan_Amount_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QChartNguyenNhan_Amount_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QChartNguyenNhan_Amount_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QChartNguyenNhan_Amount_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.SPND:
                        xtratab.Text = ReportConstants.ReportName.SPND;
                        xtratab.Name = "tab" + ReportConstants.ReportId.SPND.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.SPND;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSP_ND_Qty_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QSP_ND_Qty_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QSP_ND_Qty_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSP_ND_Qty_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSP_ND_Amount_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QSP_ND_Amount_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QSP_ND_Amount_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSP_ND_Amount_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSP_NguyenNhan_Qty_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QSP_NguyenNhan_Qty_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QSP_NguyenNhan_Qty_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSP_NguyenNhan_Qty_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSP_NguyenNhan_Amount_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QSP_NguyenNhan_Amount_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QSP_NguyenNhan_Amount_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSP_NguyenNhan_Amount_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QMachine_NG_SP_Qty_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QMachine_NG_SP_Qty_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QMachine_NG_SP_Qty_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QMachine_NG_SP_Qty_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QMachine_NG_SP_Amount_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QMachine_NG_SP_Amount_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QMachine_NG_SP_Amount_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QMachine_NG_SP_Amount_Crosstab;
                        result = true;
                        break;
                    //case ReportConstants.ReportId.FMachine_MonthlyReport:
                    //    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.FMachine_MonthlyReport);
                    //    gridView.ViewCaption = ReportConstants.ReportName.FMachine_MonthlyReport;
                    //    break;
                    case ReportConstants.ReportId.QTonglenhNhapKho1_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QTonglenhNhapKho1_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QTonglenhNhapKho1_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QTonglenhNhapKho1_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QTonglenhNG_Query_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QTonglenhNG_Query_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QTonglenhNG_Query_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QTonglenhNG_Query_Crosstab;
                        result = true;
                        break;
                    //case ReportConstants.ReportId.FNGCu_Moi:
                    //    frmDateInput fr = new frmDateInput(this);
                    //    fr.StartPosition = FormStartPosition.CenterScreen;
                    //    fr.ShowDialog();
                    //    break;
                    case ReportConstants.ReportId.QTonglenhNG_Nguyenlieu_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QTonglenhNG_Nguyenlieu_Crosstab;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QTonglenhNG_Nguyenlieu_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QTonglenhNG_Nguyenlieu_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SPQty:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SPQty;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SPQty.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SPQty;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_USD:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SP_USD;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_USD.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SP_USD;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_Qty;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_Qty;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_USD;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_USD;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_Qty;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_Qty;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_USD;
                        xtratab.Name = "tab" + ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_USD;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab;
                        xtratab.Name = "tab" +
                                       ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongOK__USD_KH_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongOK__USD_KH_Crosstab;
                        xtratab.Name = "tab" +
                                       ReportConstants.ReportId.QSSvoitonglenhgiacongOK__USD_KH_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongOK__USD_KH_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab;
                        xtratab.Name = "tab" +
                                       ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD_KH_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_USD_KH_Crosstab;
                        xtratab.Name = "tab" +
                                       ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD_KH_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_USD_KH_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab;
                        xtratab.Name = "tab" +
                                       ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab;
                        result = true;
                        break;
                    case ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD_KH_Crosstab:
                        xtratab.Text = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_USD_KH_Crosstab;
                        xtratab.Name = "tab" +
                                       ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD_KH_Crosstab.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_USD_KH_Crosstab;
                        result = true;
                        break;

                    case ReportConstants.ReportId.FInternalNG_Molist_PartList_Thuy0480:
                        xtratab.Text = ReportConstants.ReportName.FInternalNG_Molist_PartList_Thuy0480;
                        xtratab.Name = "tab" + ReportConstants.ReportId.FInternalNG_Molist_PartList_Thuy0480.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.FInternalNG_Molist_PartList_Thuy0480;
                        result = true;
                        break;

                    case ReportConstants.ReportId.FInternalNG_NGDetails:
                        xtratab.Text = ReportConstants.ReportName.FInternalNG_NGDetails;
                        xtratab.Name = "tab" + ReportConstants.ReportId.FInternalNG_NGDetails.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.FInternalNG_NGDetails;
                        result = true;
                        break;

                    //data
                    case ReportConstants.ReportId.Thuy0480:
                        xtratab.Text = ReportConstants.ReportName.Thuy0480;
                        xtratab.Name = "tab" + ReportConstants.ReportId.Thuy0480.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.Thuy0480;
                        result = true;
                        break;

                    case ReportConstants.ReportId.InternalNGDetails:
                        xtratab.Text = ReportConstants.ReportName.InternalNGDetails;
                        xtratab.Name = "tab" + ReportConstants.ReportId.InternalNGDetails.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.InternalNGDetails;
                        result = true;

                        break;

                    case ReportConstants.ReportId.MachineList:
                        xtratab.Text = ReportConstants.ReportName.MachineList;
                        xtratab.Name = "tab" + ReportConstants.ReportId.MachineList.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.MachineList;
                        result = true;
                        break;

                    case ReportConstants.ReportId.MistakeList:
                        xtratab.Text = ReportConstants.ReportName.MistakeList;
                        xtratab.Name = "tab" + ReportConstants.ReportId.MistakeList.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.MistakeList;
                        result = true;
                        break;

                    case ReportConstants.ReportId.CauseList:
                        xtratab.Text = ReportConstants.ReportName.CauseList;
                        xtratab.Name = "tab" + ReportConstants.ReportId.CauseList.ToString();
                        xtratab.Tooltip = ReportConstants.ReportName.CauseList;
                        result = true;
                        break;

                    default:
                        break;
                }
                if (result)
                {
                    xtratab.Controls.Add(uct);
                    uct.Dock = DockStyle.Fill;
                    tabControl.TabPages.Add(xtratab);
                    xtratab.Show();
                }
                else
                {
                    xtratab.Dispose();
                }

                //gridView.PopulateColumns();
                //gridView.BestFitColumns();
            }
            return result;
        }

        private void SwitchReport(int reportId)
        {
            if (ExistTab(tabControl, reportId))
            {
                foreach (XtraTabPage tabPage in tabControl.TabPages)
                {
                    if (tabPage.Name.Equals("tab" + reportId))
                    {
                        tabPage.Show();
                        break;
                    }
                }
            }
            else
            {
                // XtraTabPage xtratab = new XtraTabPage();
                ucGridView uct = new ucGridView(reportId, this.tabControl, this, this.listGV);
                switch (reportId)
                {
                    case ReportConstants.ReportId.FMachine_MonthlyReport:
                        uct.parentTab = this.tabControl;

                        frmDateMonthlyReport frMonthlyReport = new frmDateMonthlyReport(uct);
                        frMonthlyReport.StartPosition = FormStartPosition.CenterScreen;
                        frMonthlyReport.ShowDialog();
                        break;
                    case ReportConstants.ReportId.FNGCu_Moi:


                        frmDateInput fr = new frmDateInput(uct);
                        fr.StartPosition = FormStartPosition.CenterScreen;
                        fr.ShowDialog();
                        break;
                    case ReportConstants.ReportId.BusOrderofPreviousMonth:

                        this.reportId = ReportConstants.ReportId.BusOrderofPreviousMonth;
                        frmDatePreviousMonth fr2 = new frmDatePreviousMonth(uct);
                        fr2.StartPosition = FormStartPosition.CenterScreen;
                        fr2.ShowDialog();

                        break;
                    case ReportConstants.ReportId.BusOrderofThisMonth:

                        this.reportId = ReportConstants.ReportId.BusOrderofThisMonth;

                        frmDateThisMonthFrom fr3 = new frmDateThisMonthFrom(uct);
                        fr3.StartPosition = FormStartPosition.CenterScreen;
                        fr3.ShowDialog();

                        break;

                    default:
                        break;
                }
                ////xtratab.Controls.Add(uct);
                ////uct.Dock = DockStyle.Fill;
                ////tabControl.TabPages.Add(xtratab);
                ////xtratab.Show();
            }
        }

        //Export to excel button

        protected virtual void InitPopupMenu()
        {
            menu = new DXPopupMenu();
            menu.Items.Add(new DXMenuItem("Export selected row(s)", new EventHandler(OnItemExportSelectedRows), null, null, null, null));
            menu.Items.Add(new DXMenuItem("Export one tab", new EventHandler(OnItemExportAll), null, null, null, null));
            menu.Items.Add(new DXMenuItem("Export all tabs", new EventHandler(OnItemExportAlltabs), null, null, null, null));

        }

        void OnItemExportAll(object sender, EventArgs e)
        {
            string name = "GV" + tabName.Substring(3);

            foreach (GridControl view in listGV)
            {
                if (view.Name.Equals(name))
                {
                    Utilities.ExportToExcel((GridView)view.DefaultView, 1, true);
                    break;
                }
            }

        }
        void OnItemExportSelectedRows(object sender, EventArgs e)
        {
            string name = "GV" + tabName.Substring(3);

            foreach (GridControl view in listGV)
            {
                if (view.Name.Equals(name))
                {
                    Utilities.ExportToExcel((GridView)view.DefaultView, 0, true);
                    break;
                }
            }
        }
        void OnItemExportAlltabs(object sender, EventArgs e)
        {
            Utilities.ExportToExcelExtraSheet(listGV, true, ReportConstants.FormName +" ("+listGV.Count+" reports)");
        }

        //report list

        protected virtual void BindDataReportList()
        {
            cmbReportList.Items.Add(new ReportConstants.Item("Select...", -1));

            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.ChartTong, ReportConstants.ReportId.ChartTong));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QChartTong_Qty_Crosstab, ReportConstants.ReportId.QChartTong_Qty_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QChartTong_Amount_Crosstab, ReportConstants.ReportId.QChartTong_Amount_Crosstab));

            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.ChartNguyenNhanHongSanPham, ReportConstants.ReportId.ChartNguyenNhanHongSanPham));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QChartNguyenNhan_Qty_Crosstab, ReportConstants.ReportId.QChartNguyenNhan_Qty_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QChartNguyenNhan_Amount_Crosstab, ReportConstants.ReportId.QChartNguyenNhan_Amount_Crosstab));

            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.SPND, ReportConstants.ReportId.SPND));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSP_ND_Qty_Crosstab, ReportConstants.ReportId.QSP_ND_Qty_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSP_ND_Amount_Crosstab, ReportConstants.ReportId.QSP_ND_Amount_Crosstab));

            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.SPNguyenNhan, ReportConstants.ReportId.SPNguyenNhan));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSP_NguyenNhan_Qty_Crosstab, ReportConstants.ReportId.QSP_NguyenNhan_Qty_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSP_NguyenNhan_Amount_Crosstab, ReportConstants.ReportId.QSP_NguyenNhan_Amount_Crosstab));

            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.NGKhoiMay, ReportConstants.ReportId.NGKhoiMay));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QMachine_NG_SP_Qty_Crosstab, ReportConstants.ReportId.QMachine_NG_SP_Qty_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QMachine_NG_SP_Amount_Crosstab, ReportConstants.ReportId.QMachine_NG_SP_Amount_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.FMachine_MonthlyReport, ReportConstants.ReportId.FMachine_MonthlyReport));

            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.SSLenhNGVaTongLenhSX, ReportConstants.ReportId.SSLenhNGVaTongLenhSX));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.TiLeLenhLoiTrenTongSoLenh, ReportConstants.ReportId.TiLeLenhLoiTrenTongSoLenh));
            cmbReportList.Items.Add(new ReportConstants.Item("      " + ReportConstants.ReportName.QTonglenhNhapKho1_Crosstab, ReportConstants.ReportId.QTonglenhNhapKho1_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("      " + ReportConstants.ReportName.QTonglenhNG_Query_Crosstab, ReportConstants.ReportId.QTonglenhNG_Query_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.FNGCu_Moi, ReportConstants.ReportId.FNGCu_Moi));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QTonglenhNG_Nguyenlieu_Crosstab, ReportConstants.ReportId.QTonglenhNG_Nguyenlieu_Crosstab));

            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.SsVoiTongHangGiaCong, ReportConstants.ReportId.SsVoiTongHangGiaCong));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SPQty, ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SPQty));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SP_USD, ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_USD));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongNG_Qty, ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongNG_USD, ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongSP_Qty, ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongSP_USD, ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD));

            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.NGTheoCacDoiTuongKH, ReportConstants.ReportId.NGTheoCacDoiTuongKH));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab, ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongOK__USD_KH_Crosstab, ReportConstants.ReportId.QSSvoitonglenhgiacongOK__USD_KH_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab, ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongNG_USD_KH_Crosstab, ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD_KH_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab, ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.QSSvoitonglenhgiacongSP_USD_KH_Crosstab, ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD_KH_Crosstab));

            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.LenhMoi, ReportConstants.ReportId.LenhMoi));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.BusOrderofPreviousMonth, ReportConstants.ReportId.BusOrderofPreviousMonth));
            cmbReportList.Items.Add(new ReportConstants.Item("   " + ReportConstants.ReportName.BusOrderofThisMonth, ReportConstants.ReportId.BusOrderofThisMonth));

            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.FInternalNG_Molist_PartList_Thuy0480, ReportConstants.ReportId.FInternalNG_Molist_PartList_Thuy0480));
            cmbReportList.Items.Add(new ReportConstants.Item(ReportConstants.ReportName.FInternalNG_NGDetails, ReportConstants.ReportId.FInternalNG_NGDetails));

            cmbReportList.SelectedItem = cmbReportList.Items[0];

            cmbReportList.DropDown += BCThoigianlamviecthang.ReportConstants.AdjustWidthComboBox;
        }

        private void BindDataItemList()
        {
            cmbData.Items.Add(new ReportConstants.Item("Select..."));
            cmbData.Items.Add(new ReportConstants.Item(ReportConstants.Table.Thuy0480, ReportConstants.ReportId.Thuy0480));
            cmbData.Items.Add(new ReportConstants.Item(ReportConstants.Table.InternalNGDetails, ReportConstants.ReportId.InternalNGDetails));
            cmbData.Items.Add(new ReportConstants.Item(ReportConstants.Table.MachineList, ReportConstants.ReportId.MachineList));
            //cmbData.Items.Add(new ReportConstants.Item(ReportConstants.Table.MistakeList, ReportConstants.ReportId.MistakeList));
            //cmbData.Items.Add(new ReportConstants.Item(ReportConstants.Table.CauseList, ReportConstants.ReportId.CauseList));

            cmbData.SelectedItem = cmbData.Items[0];

        }

        private bool ExistTab(XtraTabControl xtraTab, int rid)
        {
            bool result = false;
            foreach (XtraTabPage tab in xtraTab.TabPages)
            {
                if (tab.Name.Equals("tab" + rid.ToString()))
                {
                    result = true;
                }
            }
            return result;
        }

        private void tabControl_CloseButtonClick(object sender, EventArgs e)
        {
            string name = "GV" + tabName.Substring(3);
            tabControl.SelectedTabPage.Dispose();

            foreach (GridControl view in listGV)
            {
                if (view.Name.Equals(name))
                {
                    
                    this.listGV.Remove(view);
                    break;
                }
            }
        }

        private void tabControl_SelectedPageChanged(object sender, TabPageChangedEventArgs e)
        {
            if (tabControl.TabPages.Count>0)
            {
                this.tabName = tabControl.SelectedTabPage.Name;
            }
        }

    }

}
